package tushu.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import tushu.Bean.RentCardBean;
import util.JDBCUtils;

public class rentCardDao {
	Connection con=null;
	PreparedStatement ps=null;
	
	public void insert(RentCardBean ren) {
		String sql="insert into b_rentcard(id,stu_name) values(?,?)";
		try {
			con=JDBCUtils.getConnection();
			ps=con.prepareStatement(sql);
			ps.setInt(1, ren.getId());
			ps.setString(2, ren.getStudentName());
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	public RentCardBean select(RentCardBean rentcard) {
		String sql="select * from b_rentcard where  id=?";
		ResultSet rs=null;
		RentCardBean rent=new RentCardBean();
		try {
			con=JDBCUtils.getConnection();
			ps=con.prepareStatement(sql);
			ps.setInt(1, rentcard.getId());
			rs=ps.executeQuery();
			while(rs.next()) {
			rent.setId(rs.getInt("id"));
			rent.setStudentName(rs.getString("stu_name"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return rent;
	}
	
}
